package com.yuan.test_jpa2.control;

import com.yuan.test_jpa2.po.Pj;
import com.yuan.test_jpa2.po.User;
import com.yuan.test_jpa2.repo.UserRepo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: usercontrol
 * @Description: TODO
 * @Author MrYuan
 * @Date: 2021/2/4 17:49
 * @Version 1.0
 */
@RestController
@Slf4j
public class usercontrol {
    @Autowired
    UserRepo up;

    /*/**
     * @Author MrYuan
     * @Date: 2021/2/20 15:39
     * @Description: page是页面索引不是limit的其实位置
     * @params:  []
     * @return: java.util.List<com.yuan.test_jpa2.po.User>
     */
    @GetMapping("a")
    private List<User> g(
    ) {
        int page = 1;
        int rows = 4;
        Pageable pageable = PageRequest.of(page, rows);
        Page<User> upAll = up.findAll(pageable);
        List<User> all = upAll.getContent();
        return all;
    }

    @GetMapping("/")
    public String gb() {
        Calendar instance = Calendar.getInstance();
        Date time1 = instance.getTime();
        instance.add(Calendar.DATE, -1);
        Date time2 = instance.getTime();
        Date date = new Date();
        List<User> allByCreateTimeBefore = up.findAllByCreateTimeAfterAndCreateTimeBefore(time2, time1);
        return "b";
    }

    @GetMapping("c")
    public List<User> gbc() {
        Calendar instance = Calendar.getInstance();
        Date time1 = instance.getTime();
        instance.add(Calendar.DATE, -10);
        Date time2 = instance.getTime();
        Date date = new Date();
        log.info(time1.toString());
        List<User> allByCreateTimeBefore = up.findAllByCreateTimeBetweenOrderByIdDesc(time2, time1);
        return allByCreateTimeBefore;
    }

    @GetMapping("d")
    public void gbc3(Pj u) {
        log.info(u.toString());
        if (u.getAge() != null) {

        }

        return;
    }

    @GetMapping("fg")
    public String get81() {
        return "81";
    }

    @GetMapping("82")
    public String get82() {
        return "82";
    }
}